﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ComLib.Logging;

namespace TwlNS {
	public partial class LoggerControl : UserControl {
		public class TextBoxLogger : LogBase {
			private readonly LoggerControl parent;
			private const string LoggerName = "LoggerControl_TextBoxLogger";
			public TextBoxLogger(LoggerControl logger):base(LoggerName){
				parent = logger;
			}
			/// <summary>
			/// Log the event to text box.
			/// </summary>
			/// <param name="logEvent"></param>
			public override void Log(LogEvent logEvent) {
				string finalMessage = logEvent.FinalMessage;
				if (string.IsNullOrEmpty(finalMessage))
					finalMessage = BuildMessage(logEvent);
				finalMessage=finalMessage.Split(new[] { ":Logger:" }, StringSplitOptions.None)[1];
				parent.txtLogger.Text += finalMessage + System.Environment.NewLine;
				parent.txtLogger.SelectionStart = parent.txtLogger.TextLength;
				parent.txtLogger.ScrollToCaret();
			}

		}

		readonly TextBoxLogger _txtBoxLogger;

		public LoggerControl() {
			InitializeComponent();
			_txtBoxLogger = new TextBoxLogger(this);
			//txtLogger.s
		}
		public ILog GetLogger() { return _txtBoxLogger; }

	}
}
